package cn.xiaye.blog.servlet;

import java.util.List;

import cn.xiaye.blog.bean.Article;
import cn.xiaye.blog.bean.Context;
import cn.xiaye.blog.bean.Keyword;
import cn.xiaye.blog.bean.Message;
import cn.xiaye.blog.bean.Sort;
import cn.xiaye.blog.dao.ArticleDao;
import cn.xiaye.blog.dao.KeywordDao;
import cn.xiaye.blog.dao.MessageDao;
import cn.xiaye.blog.dao.SortDao;

@SuppressWarnings("serial")
public class ShowMainPage extends FatherServlet {


	public String excute(Context context) {
		SortDao sortDao = new SortDao();
		List<Sort> sortList = sortDao.queryAll();

		String sortId = context.getRequest().getParameter("sort_id");
		ArticleDao articleDao = new ArticleDao();
		List<Article> articleList = null;
		if (sortId == null) {
			articleList = articleDao.queryAll();
		} else {
			articleList =articleDao.queryBySortId(Integer.valueOf(sortId));
		}

		KeywordDao keywordDao = new KeywordDao();
		List<Keyword> keywordList = keywordDao.queryAll();

		MessageDao messageDao = new MessageDao();
		List<Message> messageList = messageDao.queryAll();

		context.getRequest().setAttribute("SortList", sortList);
		context.getRequest().setAttribute("ArticleList", articleList);
		context.getRequest().setAttribute("KeywordList", keywordList);
		context.getRequest().setAttribute("MessageList", messageList);

		if (sortList.size() == 0) {
			return "none.jsp";
		} else {
			return "blog.jsp";
		}
	}
}
